const moment = require('moment')
const { sequelize } = require('@core/db-postgres')
const { Model, DataTypes } = require('sequelize')

// 定义AI模型
class Postgres extends Model {}

// 初始对话列表
AITopic.init(
    {
        id: {
            type: DataTypes.INTEGER(10).UNSIGNED,
            primaryKey: true,
            autoIncrement: true,
            comment: 'AI话题ID'
        },
        title: {
            type: DataTypes.STRING(128),
            allowNull: false,
            comment: '话题标题'
        },
        category: {
            type: DataTypes.STRING(128),
            allowNull: false,
            comment: '关联分类ID'
        },
        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            comment: '创建时间',
            get() {
                return moment(this.getDataValue('created_at')).format('YYYY-MM-DD HH:mm:ss')
            }
        },
        updated_at: {
            type: DataTypes.DATE,
            allowNull: false,
            comment: '更新时间',
            get() {
                return moment(this.getDataValue('updated_at')).format('YYYY-MM-DD HH:mm:ss')
            }
        }
    },
    {
        sequelize,
        modelName: 'aiTopic',
        tableName: 'topic'
    }
)

module.exports = {
    AITopic
}